package net.example.model;

import com.oraycn.omcs.utils.SerializeUtils;
import net.example.utils.SerializeHelper;
import java.io.IOException;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Date;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public class GroupBan {
    public int AutoID;
    public String GroupID;
    public String OperatorID;
    public String UserID;
    public String Comment;
    public Date EnableTime;
    public Date CreateTime;

    public void deserialize(byte[] bytes) throws IOException {
        ByteBuf buffer = SerializeHelper.wrappedBuffer(bytes);
        this.deserialize(buffer);
    }

    private void deserialize(ByteBuf buffer)throws IOException
    {
        buffer.readInt();
        this.AutoID = buffer.readInt();
        this.Comment = SerializeUtils.readStrIntLen(buffer);
        this.CreateTime = new Date(buffer.readLong());
        this.EnableTime=new Date(buffer.readLong());
        this.GroupID = SerializeUtils.readStrIntLen(buffer);
        this.OperatorID = SerializeUtils.readStrIntLen(buffer);
        this.UserID = SerializeUtils.readStrIntLen(buffer);
    }

    public static ArrayList<GroupBan> deserializeGroupBanList(byte[] bytes) throws IOException {
        ByteBuf buffer = Unpooled.wrappedBuffer(bytes).order(ByteOrder.LITTLE_ENDIAN);
        ArrayList<GroupBan> list = new ArrayList<GroupBan>();
        int entityCount = buffer.readInt();
        for (int i = 0; i < entityCount; i++) {
            GroupBan groupBan = new GroupBan();
            groupBan.deserialize(buffer);
            list.add(groupBan);
        }
        return list;
    }


}
